#include "led.h"

void led_fun(char *uled)
{
    uint8_t temp = 0x00;
    static uint8_t temp_old = 0xff;

    for (uint8_t i = 0; i < 8;i++)
        temp |= uled[i] << i;

        if(temp != temp_old)
        {
            GPIOC->ODR &= 0x00ff;
            GPIOC->ODR |= ~(temp << 8);

            GPIOD->BSRR |= 0x01 << 2;
            GPIOD->BRR |= 0x01 << 2;

            temp_old = temp;
        }
}

uint8_t uled[8] = {0,0,0,0,0,0,0,0};
uint32_t old_time = 0;
void led_proc(void)
{
    if (PA1.freq == PA7.freq)
    {
        uled[0] = !show_mode;
        uled[1] = show_mode;
    }
    else
    {
        uint32_t time = HAL_GetTick();
        if(time >= old_time + 100)
        {
            if(PA1.freq >PA7.freq)
            {
                uled[0] ^= 1;
                uled[1] = show_mode;
            }
            else
            {
                uled[1] ^= 1;
                uled[0] = !show_mode;
            }
            old_time = time;
        }  
    }
    uled[2] = !mode;

    led_fun(uled);
}
